```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>归并排序应用：逆序对统计 - 算法可视化</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
            line-height: 1.6;
        }
        h1, h2, h3 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .code-block {
            background-color: #1e293b;
            border-radius: 0.5rem;
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }
        .algorithm-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight {
            position: relative;
        }
        .highlight::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(167, 139, 250, 0.3);
            z-index: -1;
            transition: all 0.3s ease;
        }
        .highlight:hover::after {
            height: 50%;
            background-color: rgba(167, 139, 250, 0.5);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="container mx-auto max-w-6xl">
            <div class="flex flex-col items-center text-center">
                <div class="w-20 h-20 mb-6 rounded-full bg-white bg-opacity-20 flex items-center justify-center">
                    <i class="fas fa-sort-amount-down-alt text-3xl"></i>
                </div>
                <h1 class="text-4xl md:text-5xl font-bold mb-4">归并排序应用</h1>
                <h2 class="text-2xl md:text-3xl font-semibold mb-6">逆序对统计的<span class="highlight">高效解法</span></h2>
                <p class="text-xl max-w-3xl opacity-90 mb-8">
                    探索如何利用分治思想，在归并排序过程中高效统计数组中的逆序对数量。这是一个展示算法优化思维的经典案例。
                </p>
                <div class="flex space-x-4">
                    <a href="#problem" class="px-6 py-3 bg-white text-indigo-600 font-medium rounded-lg hover:bg-opacity-90 transition duration-300">
                        <i class="fas fa-question-circle mr-2"></i>问题描述
                    </a>
                    <a href="#solution" class="px-6 py-3 border-2 border-white text-white font-medium rounded-lg hover:bg-white hover:bg-opacity-10 transition duration-300">
                        <i class="fas fa-lightbulb mr-2"></i>解决方案
                    </a>
                </div>
            </div>
        </div>
    </div>

    <!-- Problem Section -->
    <div id="problem" class="py-16 px-6 bg-white">
        <div class="container mx-auto max-w-6xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0 md:pr-10">
                    <h2 class="text-3xl font-bold mb-6 text-gray-800">问题描述</h2>
                    <p class="text-lg text-gray-700 mb-6">
                        给定一个数组，统计其中的<span class="font-semibold text-indigo-600">逆序对</span>数量。逆序对指的是数组中前面的数大于后面的数。
                    </p>
                    <div class="bg-gray-100 p-6 rounded-lg border-l-4 border-indigo-500 mb-8">
                        <h3 class="font-semibold text-lg mb-3">示例</h3>
                        <p class="mb-2">输入数组: [7, 5, 6, 4]</p>
                        <p>逆序对: (7,5), (7,6), (7,4), (5,4), (6,4) → 共5个</p>
                    </div>
                    <div class="flex items-center text-indigo-600">
                        <i class="fas fa-exclamation-circle mr-2"></i>
                        <span>暴力解法时间复杂度为O(n²)，我们需要更高效的算法</span>
                    </div>
                </div>
                <div class="md:w-1/2">
                    <div class="relative">
                        <div class="absolute inset-0 bg-indigo-100 rounded-xl transform rotate-1"></div>
                        <div class="relative bg-white p-8 rounded-xl shadow-lg border border-gray-200">
                            <h3 class="text-xl font-bold mb-4 text-gray-800">直观理解逆序对</h3>
                            <div class="mermaid">
                                graph TD
                                    A[7,5,6,4] --> B[比较7>5]
                                    A --> C[比较7>6]
                                    A --> D[比较7>4]
                                    B --> E[形成逆序对 (7,5)]
                                    C --> F[形成逆序对 (7,6)]
                                    D --> G[形成逆序对 (7,4)]
                                    B --> H[继续比较5和6]
                                    H --> I[5<=6, 不计数]
                                    H --> J[继续比较5和4]
                                    J --> K[形成逆序对 (5,4)]
                                    C --> L[继续比较6和4]
                                    L --> M[形成逆序对 (6,4)]
                            </div>
                            <p class="mt-4 text-gray-600 text-sm">
                                图示: 暴力解法需要比较所有可能的数对，共n(n-1)/2次比较
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Solution Section -->
    <div id="solution" class="py-16 px-6 bg-gray-50">
        <div class="container mx-auto max-w-6xl">
            <div class="text-center mb-16">
                <h2 class="text-3xl font-bold mb-4 text-gray-800">基于归并排序的解决方案</h2>
                <p class="text-xl text-gray-600 max-w-3xl mx-auto">
                    利用分治思想，在归并排序的合并过程中统计逆序对，将时间复杂度优化到<span class="font-semibold text-indigo-600">O(n log n)</span>
                </p>
            </div>

            <div class="grid md:grid-cols-3 gap-8 mb-16">
                <div class="algorithm-card bg-white p-8 rounded-xl shadow-md transition duration-300">
                    <div class="w-12 h-12 mb-4 rounded-lg bg-indigo-100 text-indigo-600 flex items-center justify-center">
                        <i class="fas fa-code-branch text-xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">分治策略</h3>
                    <p class="text-gray-600">
                        将数组分成两半，分别计算左半部分、右半部分的逆序对数，以及跨越两部分的逆序对数
                    </p>
                </div>
                <div class="algorithm-card bg-white p-8 rounded-xl shadow-md transition duration-300">
                    <div class="w-12 h-12 mb-4 rounded-lg bg-indigo-100 text-indigo-600 flex items-center justify-center">
                        <i class="fas fa-random text-xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">归并过程</h3>
                    <p class="text-gray-600">
                        在合并两个已排序数组时，当左半部分元素大于右半部分元素时，计数增加
                    </p>
                </div>
                <div class="algorithm-card bg-white p-8 rounded-xl shadow-md transition duration-300">
                    <div class="w-12 h-12 mb-4 rounded-lg bg-indigo-100 text-indigo-600 flex items-center justify-center">
                        <i class="fas fa-calculator text-xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">高效计算</h3>
                    <p class="text-gray-600">
                        利用数组已排序的性质，可以批量计算逆序对数，而不是逐个比较
                    </p>
                </div>
            </div>

            <div class="bg-white rounded-xl overflow-hidden shadow-lg mb-16">
                <div class="md:flex">
                    <div class="md:w-1/2 p-8">
                        <h3 class="text-2xl font-bold mb-6 text-gray-800">算法步骤解析</h3>
                        <div class="space-y-6">
                            <div class="flex">
                                <div class="flex-shrink-0 mr-4">
                                    <div class="flex items-center justify-center h-10 w-10 rounded-full bg-indigo-100 text-indigo-600">
                                        <span class="font-bold">1</span>
                                    </div>
                                </div>
                                <div>
                                    <h4 class="text-lg font-semibold text-gray-800">分解</h4>
                                    <p class="text-gray-600">将数组递归地分成两半，直到子数组长度为1</p>
                                </div>
                            </div>
                            <div class="flex">
                                <div class="flex-shrink-0 mr-4">
                                    <div class="flex items-center justify-center h-10 w-10 rounded-full bg-indigo-100 text-indigo-600">
                                        <span class="font-bold">2</span>
                                    </div>
                                </div>
                                <div>
                                    <h4 class="text-lg font-semibold text-gray-800">合并与计数</h4>
                                    <p class="text-gray-600">合并两个有序子数组时，当左元素大于右元素时，左半部分剩余元素都构成逆序对</p>
                                </div>
                            </div>
                            <div class="flex">
                                <div class="flex-shrink-0 mr-4">
                                    <div class="flex items-center justify-center h-10 w-10 rounded-full bg-indigo-100 text-indigo-600">
                                        <span class="font-bold">3</span>
                                    </div>
                                </div>
                                <div>
                                    <h4 class="text-lg font-semibold text-gray-800">累加结果</h4>
                                    <p class="text-gray-600">将左半部分、右半部分和跨部分的逆序对数相加，得到总逆序对数</p>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="md:w-1/2 bg-gray-50 p-8">
                        <div class="mermaid">
                            graph TD
                                A[原数组] --> B[拆分]
                                B --> C[左子数组]
                                B --> D[右子数组]
                                C --> E[递归排序并计数]
                                D --> F[递归排序并计数]
                                E --> G[左逆序对数]
                                F --> H[右逆序对数]
                                G --> I[合并并计算跨逆序对数]
                                H --> I
                                I --> J[总逆序对数 = 左 + 右 + 跨]
                        </div>
                    </div>
                </div>
            </div>

            <div class="mb-16">
                <h3 class="text-2xl font-bold mb-6 text-gray-800">Python 实现代码</h3>
                <div class="code-block p-6 text-gray-200 overflow-x-auto">
                    <pre><code class="language-python">
def mergeSortInversions(nums):
    def merge(left, right):
        result = []
        count = 0
        i = j = 0
        while i < len(left) and j < len(right):
            if left[i] <= right[j]:
                result.append(left[i])
                i += 1
            else:
                result.append(right[j])
                count += len(left) - i
                j += 1
        result.extend(left[i:])
        result.extend(right[j:])
        return result, count
    
    def sort(nums):
        if len(nums) <= 1:
            return nums, 0
        mid = len(nums) // 2
        left, left_count = sort(nums[:mid])
        right, right_count = sort(nums[mid:])
        merged, merge_count = merge(left, right)
        return merged, left_count + right_count + merge_count
    
    return sort(nums)[1]
                    </code></pre>
                </div>
            </div>

            <div class="bg-white rounded-xl p-8 shadow-lg">
                <h3 class="text-2xl font-bold mb-6 text-gray-800">算法复杂度分析</h3>
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <h4 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                            <i class="fas fa-clock mr-2 text-indigo-600"></i>
                            时间复杂度分析
                        </h4>
                        <div class="mermaid">
                            pie title 时间复杂度
                                "分解" : 1
                                "解决子问题" : 2*T(n/2)
                                "合并" : n
                        </div>
                        <p class="mt-4 text-gray-600">
                            根据主定理，归并排序的时间复杂度为O(n log n)，统计逆序对的操作不影响整体复杂度
                        </p>
                    </div>
                    <div>
                        <h4 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                            <i class="fas fa-memory mr-2 text-indigo-600"></i>
                            空间复杂度分析
                        </h4>
                        <div class="bg-gray-100 p-6 rounded-lg">
                            <div class="flex items-center mb-3">
                                <div class="w-4 h-4 bg-indigo-500 mr-2"></div>
                                <span class="font-medium">O(n)</span>
                            </div>
                            <p class="text-gray-600">
                                需要额外的空间存储临时数组，与标准归并排序相同
                            </p>
                            <div class="mt-4 flex items-center">
                                <div class="w-4 h-4 bg-indigo-300 mr-2"></div>
                                <span class="font-medium">O(log n)</span>
                            </div>
                            <p class="text-gray-600">
                                递归调用栈的深度为log n
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            pie: {
                useWidth: 400,
                useHeight: 300,
                showData: true
            }
        });
    </script>
</body>
</html>
```